<template>
  <div class="fuwenben">
    <div id="div1" style="width: 100%; color: #000;"></div>
  </div>
</template>

<script>
  import * as qiniu from 'qiniu-js'
  import E from "wangeditor"
  export default {
    name: 'fuwenben',
    props:['content'],
    data() {
      return {
        content:""
      }
    },
    created() {

    },
    beforeDestroy() {

    },
    mounted() {
      var that = this
      const editor = new E("#div1")
      editor.config.height = 250
      editor.config.colors = [
          '#000000',
          '#eeece0',
          '#1c487f',
          '#4d80bf'
      ]
      editor.config.uploadImgServer = '/upload'
      editor.config.showLinkImg = false
      editor.config.onchange = function(html) {
      	that.content = html
        that.$emit('getcontent',html)
      }
      editor.config.customUploadImg = function(files, insert) {
        console.log(files)
        axios.post(`apis/shangchuan`,{kongjian:'yantaidongfeng',name:`a.jpg`})
          .then(response => {
            const observer = {
              next(res){
                console.log('next')
                console.log(res)
              },
              error(err){
                console.log('err')
                console.log(err)
              },
              complete(res){
                console.log('complete')
                console.log(res)
                // insert('http://127.0.0.1:8000/storage/'+response.data.data)
              }
            }

            let file = new File([files[0]], `a.jpg`, {type: 'image/jpeg'});
            const observable = qiniu.upload(file, `a.jpg`, response.data, {}, {})
            const subscription = observable.subscribe(observer) // 上传开始
          });
      }
      editor.create()
      
      if(this.content){
        editor.txt.html(this.content)
      }
      
    },
    methods: {
      // fabu: function() {
      // 	this.ing = true
      // 	axios.post(`${this.url}/admin/addarticle`,this.all)
      // 	  .then(response => {
      // 	    this.ing = false
      // 	    if(response.data.code == 0){
      //         this.$message.success('发布成功');
      // 	    }else{
      //         this.$message.error(response.data.msg.info);
      //       }
      // 	  })
      // },
    }
  }
</script>


<style scoped lang="less">
  .wenzhang_add{

  }
</style>
